home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11.lha / ccs-lib / tools / convert / tovida.c < prev   
Encoding:
C/C++ Source or Header  |  1992-10-15  |  2.3 KB  |  122 lines

  1. /*
  2. %
  3. %    TOVIDA . C
  4. %
  5. %    The format for the input file is any image.
  6. %    The format for the output file is a color RLE file,
  7. */
  8. char    usage[]="\
  9. -k        keep going when error hanppened\n\
  10. -o name_string    out going file name\n\
  11. [<] input\n";
  12. /*
  13. % AUTHOR:    Jin Guojun, LBL - 1991
  14. */
  15.  
  16. #include "header.def"
  17. #include "imagedef.h"
  18.  
  19. typedef    struct    {
  20.     int    size;
  21.     char    data_type[10],
  22.         name[18];
  23.     int    extents;
  24.     short    session_error;
  25.     char    regular,
  26.         hkey_un0;
  27.     }hdr_key;
  28.  
  29. typedef    struct    {
  30.     short    dim[15],
  31.         datatype,
  32.         bitpix,
  33.         dim_un0;
  34.     float    pixdim[16];
  35.     int    glmax, glmin;
  36.     } image_dim;
  37.  
  38. typedef    struct    {
  39.     char    descrip[80],
  40.         aux_file[24],
  41.         orient,
  42.         originator[10],
  43.         generated[10],
  44.         scannum[10],
  45.         patient_id[10],
  46.         exp_date[10],
  47.         exp_time[10],
  48.         hist_un0[3];
  49.     int    vieww,
  50.         vols_added,
  51.         start_field,
  52.         omax, omin,
  53.         smax, smin;
  54.     } hdr_history;
  55.  
  56. typedef    struct    {
  57.     hdr_key        key;
  58.     image_dim    img;
  59.     hdr_history    his;
  60.     } analyze_db;
  61.  
  62. analyze_db    idb;
  63. U_IMAGE    uimg;
  64. bool    nostop;
  65. #define    rows    uimg.height
  66. #define    cols    uimg.width
  67.  
  68. main(ac, av)
  69. int    ac;
  70. char*    av[];
  71. {
  72. char    *fname, ofname[64];
  73. int    row;
  74. FILE    *hdf;
  75.  
  76. format_init(&uimg, IMAGE_INIT_TYPE, HIPS, HIPS, *av, "D20-1");
  77.  
  78. for (row=1; row<ac; row++)
  79.     if (*av[row] == '-') {
  80.     switch (av[row][1])
  81.     {
  82.     case 'k':    nostop++;    break;
  83.     case 'o':    fname = av[++row];    break;
  84.     default:
  85. errout:        usage_n_options(usage, row, av[row]);
  86.     }
  87.     }
  88.     else if (freopen(uimg.name=av[row], "rb", stdin) != stdin)
  89.         syserr("input file -- %s", av[row]);
  90.  
  91. io_test(fileno(in_fp), goto    errout);
  92. strncpy(idb.key.name, uimg.name, 17);
  93. if (!fname)
  94.     fname = uimg.name;
  95. strcpy(ofname, fname);
  96. strcat(ofname, ".hdr");
  97. hdf = fopen(ofname, "w");
  98. strcpy(ofname, fname);
  99. strcat(ofname, ".img");
  100. out_fp = freopen(ofname, "wb", stdout);
  101. if (!hdf || !out_fp)
  102.     syserr("open file %s", fname);
  103.  
  104.     if ((*uimg.header_handle)(HEADER_READ, &uimg, 0, 0, 0) < 0)
  105.         syserr("unknown image type");
  106.  
  107.     (*uimg.std_swif)(FI_LOAD_FILE, &uimg, nostop ? NULL : uimg.name, 0);
  108.  
  109.     idb.key.size = sizeof(idb);
  110.     idb.img.dim[0] = cols;
  111.     idb.img.dim[1] = rows;
  112.     idb.img.dim[2] = uimg.frames;
  113.     idb.img.pixdim[0] = 1.0;
  114.     idb.img.pixdim[1] = 1.0;
  115.     idb.img.pixdim[2] = 1.0;
  116.     idb.img.datatype = uimg.in_form==IFMT_SHORT ? 4 : 2;
  117.     idb.img.bitpix = (uimg.pxl_out=uimg.pxl_in) << 3;
  118.  
  119.     fwrite(&idb, sizeof(idb), 1, hdf);    /* write header */
  120.     (*uimg.std_swif)(FI_SAVE_FILE, &uimg, No, NULL); /* output data */
  121. }
  122.